var mongodb = require('./momongodb');
var Schema = mongodb.mongoose.Schema;
SensorOutput = function(_devName,_devNo,_content,_value,_date){
	this.DevName = _devName;
	this.DevNo = _devNo;
	this.MonitorContent = _content;
	this.MonitorValue = _value;
	this.MonitorDate = _date;
};
var DeviceStatusSchema = new Schema({
  DevName: String,
  DevNo: Number,
  MonitorContent: String,
  MonitorValue: String,
  MonitorDate: Date,
  CreateDate:{type: Date, default: Date.now},
});
var DeviceStatus = mongodb.mongoose.model("DeviceStatus", DeviceStatusSchema);
var DeviceStatusDAO = function(){};
DeviceStatusDAO.prototype.save = function(obj, callback) {
  var instance = new DeviceStatus(obj);
  instance.save(function(err){
  callback(err);
  //console.log(err);
  });
};
DeviceStatusDAO.prototype.findByName = function(name, callback) {
  DeviceStatus.findOne({DevName:name}, function(err, obj){
  callback(err, obj);
  });
};
DeviceStatusDAO.prototype.getAllStatus = function(callback) {
  console.log('test');
  DeviceStatus.find({DevNo:{$gte:0}},function(err, obj){
  callback(err, obj);
  });
};
DeviceStatusDAO.prototype.findByIdAndUpdate = function(obj,callback){
  var _id=obj.DevName;
  //delete obj.DevName;
  DeviceStatus.findOneAndUpdate({DevName: obj.DevName}, obj, {upsert: true},function(err,obj){
    callback(err, obj);
    //console.log(err);
  });
}
module.exports = new DeviceStatusDAO();